from  bs4 import BeautifulSoup
class film():
    def __init__(self,name,star,releasetime,score):
        self.name=name
        self.star=star
        self.releasetime=releasetime
        self.score=score
text=''
with open('猫眼100.html','r',encoding='utf-8') as f:
    text=f.read()
soup=BeautifulSoup(text,'lxml')
divs=soup.select("div[class='movie-item-info']")
films=[]
for d in divs:
    name=d.select("p[class='name'] a")[0].get_text()
    star=d.select("p[class='star']")[0].get_text().strip()
    releasetime=d.select("p[class='releasetime']")[0].get_text().strip()
    sc=d.find_next_sibling().select("p[class='score'] i")
    score =sc[0].get_text()+sc[1].get_text()
    fi=film(name,star,releasetime,score)
    films.append(fi)
for index,film in enumerate(films):
    print(f'第{index+1}名',film.name, film.star, film.releasetime,film.score)
